<script setup lang="ts">
import { ref } from "vue";
import { useRoute } from "vue-router";
import router from "@/router";
import HeaderOperateLeft from "./Child/HeaderOperateLeft.vue";
import HeaderOperateRight from "./Child/HeaderOperateRight.vue";
import { useAddEvent, useRemoveEvent } from "@/hooks/usewindow";
const route = useRoute();
const bgflag = ref(true);
const setBg = () => {
  if (route.path === "/") {
    if (document.documentElement.scrollTop > 175) {
      bgflag.value = false;
    } else {
      bgflag.value = true;
    }
  } else {
    bgflag.value = false;
  }
};
useAddEvent("scroll", setBg);
useRemoveEvent("scroll", setBg);
</script>

<template>
  <header
    class="header-nav"
    :style="
      bgflag ? 'background-color: transparent;' : 'background-color: #fff;'
    "
  >
    <div class="header-nav-container">
      <a href="#" class="logo" @click="router.push('/')">
        <img
          class="logo-pc"
          src="https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg"
          alt="logo"
        />
        <img
          class="logo-mobile"
          src="https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/6c61ae65d1c41ae8221a670fa32d05aa.svg"
          alt="mobile"
        />
      </a>
      <nav class="nav-header">
        <HeaderOperateLeft />
        <HeaderOperateRight :bgflag="bgflag" />
      </nav>
    </div>
  </header>
</template>

<style scoped lang="less">
.header-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  // border-bottom: 1px solid #f1f1f1;
  background-color: transparent;
  overflow: hidden;
  z-index: 12;
  user-select: none;
  transition: all 0.3s linear;
  &-container {
    display: flex;
    max-width: 1440px;
    height: 60px;
    line-height: 60px;
    margin: auto;
    img {
      vertical-align: middle;
    }

    .logo {
      margin-right: 12.5px;
      margin-left: 16px;
      width: auto;
      .logo-pc {
        width: 107px;
        margin: auto;
        margin-bottom: 3px;
      }
      .logo-mobile {
        display: none;
      }
    }

    .nav-header {
      flex: 1;
      display: flex;
      justify-content: space-between;
      align-items: center;
      text-align: center;
      font-size: 14px;
    }
  }
}
</style>
